//
//  UIView+KKShorthandAdditions.h
//  KKonry
//
//  Created by Jonas Budelmann on 22/07/13.
//  Copyright (c) 2013 Jonas Budelmann. All rights reserved.
//

#import "View+KKAdditions.h"

#ifdef KK_SHORTHAND

/**
 *	Shorthand view additions without the 'KK_' prefixes,
 *  only enabled if KK_SHORTHAND is defined
 */
@interface KK_VIEW (KKShorthandAdditions)

@property (nonatomic, strong, readonly) KKViewAttribute *left;
@property (nonatomic, strong, readonly) KKViewAttribute *top;
@property (nonatomic, strong, readonly) KKViewAttribute *right;
@property (nonatomic, strong, readonly) KKViewAttribute *bottom;
@property (nonatomic, strong, readonly) KKViewAttribute *leading;
@property (nonatomic, strong, readonly) KKViewAttribute *trailing;
@property (nonatomic, strong, readonly) KKViewAttribute *width;
@property (nonatomic, strong, readonly) KKViewAttribute *height;
@property (nonatomic, strong, readonly) KKViewAttribute *centerX;
@property (nonatomic, strong, readonly) KKViewAttribute *centerY;
@property (nonatomic, strong, readonly) KKViewAttribute *baseline;
@property (nonatomic, strong, readonly) KKViewAttribute *(^attribute)(NSLayoutAttribute attr);

@property (nonatomic, strong, readonly) KKViewAttribute *firstBaseline;
@property (nonatomic, strong, readonly) KKViewAttribute *lastBaseline;

#if TARGET_OS_IPHONE || TARGET_OS_TV

@property (nonatomic, strong, readonly) KKViewAttribute *leftMargin;
@property (nonatomic, strong, readonly) KKViewAttribute *rightMargin;
@property (nonatomic, strong, readonly) KKViewAttribute *topMargin;
@property (nonatomic, strong, readonly) KKViewAttribute *bottomMargin;
@property (nonatomic, strong, readonly) KKViewAttribute *leadingMargin;
@property (nonatomic, strong, readonly) KKViewAttribute *trailingMargin;
@property (nonatomic, strong, readonly) KKViewAttribute *centerXWithinMargins;
@property (nonatomic, strong, readonly) KKViewAttribute *centerYWithinMargins;

#endif

#if TARGET_OS_IPHONE || TARGET_OS_TV

@property (nonatomic, strong, readonly) KKViewAttribute *safeAreaLayoutGuideLeading NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *safeAreaLayoutGuideTrailing NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *safeAreaLayoutGuideLeft NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *safeAreaLayoutGuideRight NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *safeAreaLayoutGuideTop NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *safeAreaLayoutGuideBottom NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *safeAreaLayoutGuideWidth NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *safeAreaLayoutGuideHeight NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *safeAreaLayoutGuideCenterX NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) KKViewAttribute *safeAreaLayoutGuideCenterY NS_AVAILABLE_IOS(11.0);

#endif

- (NSArray *)makeConstraints:(void(^)(KKConstraintMaker *make))block;
- (NSArray *)updateConstraints:(void(^)(KKConstraintMaker *make))block;
- (NSArray *)remakeConstraints:(void(^)(KKConstraintMaker *make))block;

@end

#define KK_ATTR_FORWARD(attr)  \
- (KKViewAttribute *)attr {    \
    return [self KK_##attr];   \
}

#define KK_ATTR_FORWARD_AVAILABLE(attr, available)  \
- (KKViewAttribute *)attr available {    \
    return [self KK_##attr];   \
}

@implementation KK_VIEW (KKShorthandAdditions)

KK_ATTR_FORWARD(top);
KK_ATTR_FORWARD(left);
KK_ATTR_FORWARD(bottom);
KK_ATTR_FORWARD(right);
KK_ATTR_FORWARD(leading);
KK_ATTR_FORWARD(trailing);
KK_ATTR_FORWARD(width);
KK_ATTR_FORWARD(height);
KK_ATTR_FORWARD(centerX);
KK_ATTR_FORWARD(centerY);
KK_ATTR_FORWARD(baseline);

KK_ATTR_FORWARD(firstBaseline);
KK_ATTR_FORWARD(lastBaseline);

#if TARGET_OS_IPHONE || TARGET_OS_TV

KK_ATTR_FORWARD(leftMargin);
KK_ATTR_FORWARD(rightMargin);
KK_ATTR_FORWARD(topMargin);
KK_ATTR_FORWARD(bottomMargin);
KK_ATTR_FORWARD(leadingMargin);
KK_ATTR_FORWARD(trailingMargin);
KK_ATTR_FORWARD(centerXWithinMargins);
KK_ATTR_FORWARD(centerYWithinMargins);

KK_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideLeading, NS_AVAILABLE_IOS(11.0));
KK_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideTrailing, NS_AVAILABLE_IOS(11.0));
KK_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideLeft, NS_AVAILABLE_IOS(11.0));
KK_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideRight, NS_AVAILABLE_IOS(11.0));
KK_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideTop, NS_AVAILABLE_IOS(11.0));
KK_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideBottom, NS_AVAILABLE_IOS(11.0));
KK_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideWidth, NS_AVAILABLE_IOS(11.0));
KK_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideHeight, NS_AVAILABLE_IOS(11.0));
KK_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideCenterX, NS_AVAILABLE_IOS(11.0));
KK_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideCenterY, NS_AVAILABLE_IOS(11.0));

#endif

- (KKViewAttribute *(^)(NSLayoutAttribute))attribute {
    return [self KK_attribute];
}

- (NSArray *)makeConstraints:(void(NS_NOESCAPE ^)(KKConstraintMaker *))block {
    return [self KK_makeConstraints:block];
}

- (NSArray *)updateConstraints:(void(NS_NOESCAPE ^)(KKConstraintMaker *))block {
    return [self KK_updateConstraints:block];
}

- (NSArray *)remakeConstraints:(void(NS_NOESCAPE ^)(KKConstraintMaker *))block {
    return [self KK_remakeConstraints:block];
}

@end

#endif
